<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function foo(x, y, z) {
      console.log(x + y + z)
    }
    function sum(num1, num2) {
      return num1 + num2
    }
    function logInfo(date, type, message) {
      console.log(`时间:${date} 类型:${type} 内容:${message}`)
    }

    var names = ['abc', 'cba', 'nba']
    console.log(names)
    console.log(...names)


    // 手动转换
    // 自动转换
    function hyCurrying(fn) {
      function curryFn(...args) {
        // 两类操作
        // 1. 继续返回一个新的函数,继续接受参数
        // 2. 执行fn的函数
        if (args.length >= fn.length) {
          // return fn(...args)
          return fn.apply(this, args)
        } else {
          return function (...newArgs) {
            // return curryFn(...args.concat(newArgs))
            return curryFn.apply(this, args.concat(newArgs))
          }
        }
      }
      return curryFn
    }
    // 对其他函数进行柯里化
    var fooCurry = hyCurrying(foo)
    fooCurry(10)(20)(30)
    fooCurry(55, 12, 56)

    var sumCurry = hyCurrying(sum)
    var sum5 = sumCurry(5)
    console.log(sumCurry(10)(20))
    console.log(sum5(10))

    var logCurry = hyCurrying(logInfo)
    logCurry("2022-12-20")("Info")("你好")


  </script>
</body>

</html>